package com.wlc.fanxing;

import com.wlc.collection.Hero;

import java.util.LinkedList;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description HeroStack
 * @date 2021-07-13 15:40
 */
public class HeroStack {
    LinkedList<Hero> heros = new LinkedList<Hero>();

    /**
     * 添加到最后
     * @param h
     */
    public void push(Hero h) {
        heros.addLast(h);
    }

    /**
     * 把链表的最后一个元素移除
     * @return
     */
    public Hero pull() {
        return heros.removeLast();
    }

    /**
     * 获取最后一个元素
     * @return
     */
    public Hero peek() {
        return heros.getLast();
    }

    public static void main(String[] args) {

        HeroStack heroStack = new HeroStack();
        for (int i = 0; i < 5; i++) {
            Hero h = new Hero("hero name " + i);
            System.out.println("压入 hero:" + h);
            heroStack.push(h);
        }
        Hero peek = heroStack.peek();
        System.out.println("peek = " + peek);
        for (int i = 0; i < 5; i++) {
            Hero h =heroStack.pull();
            System.out.println("弹出 hero" + h);
        }
    }
}
